/*
 * Created on Dec 23, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ba360.struts.action;

import java.io.FileInputStream;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ba360.struts.form.AttractionsBean;
import com.ba360.struts.form.MainAttraction;
import com.wutka.jox.JOXBeanInputStream;

/**
 * @author ROnat
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class AttractionsAction extends Action {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest req, HttpServletResponse res) throws Exception {
		// TODO Auto-generated method stub
		HttpSession session = req.getSession();
		String type = req.getParameter("attName");
		MainAttraction[] ab = null;
		String[] attName;
		String forward;
		ResourceBundle rb = ResourceBundle.getBundle("ApplicationResources");
		FileInputStream in = new FileInputStream(rb.getString("AttractionsDB"));

		JOXBeanInputStream joxIn = new JOXBeanInputStream(in);

		AttractionsBean testBean = new AttractionsBean();
		joxIn.readObject(testBean);
		ab = testBean.getMainAttraction();

		if (type == null) {
			//Log.in(ab.length);
			attName = new String[ab.length];

			for (int i = 0; i < ab.length; i++) {
				attName[i] = ab[i].getName();

			}
			session.setAttribute("AttInfo", testBean.getInfo());
			session.setAttribute("MainAttInfo", ab);
			forward = "success";
		} else {

			String mainAttName = req.getParameter("attName");
		//	System.out.println(mainAttName+"  "+ab.length);

			for (int i = 0; i < ab.length; i++) {
				if (ab[i].getName().equals(mainAttName)) {
					session.setAttribute("AttInfo", ab[i].getAttraction());
				}

			}
			forward = "businessinfo";
		}

		return mapping.findForward(forward);
	}
}